﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TestXNA3.Actors;
using TestXNA3.Resources;
using TestXNA3.Render;
using Microsoft.Xna.Framework;
using System.IO;
using TestXNA3.Generic;
using System.Runtime.Serialization;

namespace TestXNA3.Components
{
    [Serializable]
    public abstract class Component : ISerializable
    {
        public enum EUpdateGroup
        {
            PreUpdate,
            PostUpdate
        };

        private Actor _parent;
        public Actor Parent
        {
            get { return _parent; }
            set { _parent = value; parentSet(); }
        }

        public EUpdateGroup UpdateGroup;
        public bool CanAffectParentAxis;
        public bool UseAsParentTracer = false;
        public bool Saveable = true;

        public Component()
        {
            Parent = null;
            UpdateGroup = EUpdateGroup.PostUpdate;
            CanAffectParentAxis = false;
        }

        public virtual void AddToRenderQueue(SceneRenderer sceneRenderer, ref List<MeshResource> meshes)
        {
        }

        public virtual void Update(float dt)
        {
        }

        protected virtual void parentSet()
        {
        }

        public virtual void notifyActorAxisChanged()
        {
        }

        public virtual void notifyActorScaleChanged()
        {
        }

        public virtual void Save(BinaryWriter writer)
        {
        }

        public virtual void Load(BinaryReader reader)
        {
        }

        public virtual void MapFullyLoaded(Map map)
        {
        }

        public virtual bool Trace(Vector3 start, Vector3 end, ref float T)
        {
            return false;
        }

        public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Saveable", Saveable);

            if (!Saveable)
                return;

            info.AddValue("Parent", Parent);
            info.AddValue("UpdateGroup", UpdateGroup);
            info.AddValue("CanAffectParentAxis", CanAffectParentAxis);
            info.AddValue("UseAsParentTracer", UseAsParentTracer);
        }
    }
}
